package com.example.smartlearning.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartlearning.dao.NewDao;
import com.example.smartlearning.dao.QuanZiDao;
import com.example.smartlearning.dao.TopicQuanZiDao;
import com.example.smartlearning.entity.NewEntity;
import com.example.smartlearning.entity.QuanZiEntity;
import com.example.smartlearning.entity.ResultEntity;
import com.example.smartlearning.service.NewService;
import com.example.smartlearning.service.QuanZiService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class QuanZiServiceImpl extends ServiceImpl<QuanZiDao, QuanZiEntity> implements QuanZiService {

    private static final Logger logger = LoggerFactory.getLogger(QuanZiServiceImpl.class);//日志。getLogger需要传入当前的类名

    @Resource
    QuanZiDao quanZiDao;

    @Resource
    TopicQuanZiDao topicQuanZiDao;
    @Override
    public String getAll() {
        try {
            return ResultEntity.success(quanZiDao.getAll());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    @Override
    public String getAllById(int id) {
        try {
            return ResultEntity.success(quanZiDao.getAllById(id));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    @Override
    public String addNew(int userId, int quanZiId) {
        try {
            quanZiDao.addNum(quanZiId);
            return ResultEntity.success(quanZiDao.addNew(userId, quanZiId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }

    @Override
    public String getTopic(int topicId) {
        try {
            return ResultEntity.success(topicQuanZiDao.selectByTopicId(topicId));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getLocalizedMessage());
            return ResultEntity.fail(-10004);
        }
    }
}
